/**
 * Description:
 *
 * @author      Eden
 * @datetime    2016/11/25 19:58
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */


(function () {

    "use strict";

    var api = {
        doAuditUrl: "/user/purchaser/doAudit"
    };

    sm.controller("admin-purchaser-user-index", ['$scope', '$http', 'Modal', function ($scope, $http, Modal) {

        $scope.alertImage = false;

        // 选择
        $scope.alert = function (id) {

            if (!id) {
                return false;
            }

            Modal.alert({
                title: '操作提示',
                content: "请选择以下操作项",
                buttons: [{
                    name: "取消",
                }, {
                    name: "拒绝",
                    event: function () {
                        console.log('reject');
                        doAudit(id, "reject");
                    }
                }, {
                    name: "通过",
                    event: function () {
                        console.log('pass');
                        doAudit(id, "pass");
                    }
                }]
            });
        };

        function doAudit(id, action) {
            $http.post(api.doAuditUrl, {
                "id": id,
                "action": action
            }).success(function (res) {
                if (res.state) {
                    // do dom
                    var html = "";
                    switch (action) {
                        case "reject":
                            html = '<span class="text-danger">拒绝</span>';
                            break;
                        case "pass":
                            html = '<span class="text-success">通过</span>';
                            break;
                    }
                    $("#item-" + id).html(html)
                } else {
                    Modal.error(res.error);
                }
            });
        }

        $scope.showImage = function (imgUrl) {
            $('#imageModal').modal();
            $scope.imgUrl = imgUrl;
            $scope.alertImage = true;
        };



    }]);



})();
